/**
 * 盈亏分析
 */
import api from '../../../api';
import { message } from 'antd';
export default {
  namespace: 'profitAndLossAnalysisM',

  state: {},

  effects: {
    // 获取区间维度信息 区间盈亏
    *getEchartDate1({ payload, callback }, { call, put }) {
      const response = yield call(api.profitOverview.getEchartDate1, payload);
      if (response && response.code == 0) {
        callback(response, 'sucess');
      } else {
        callback('faill');
        message.error(response && response.msg ? response.msg : '查询失败');
        console.error(`获取区间盈亏数据失败，失败原因：${response?.msg}`, '接口名称：intervalCount/ 接口：portfoliopnl/intervalCount/');
      }
    },

    // 获取资产维度统计信息 资产类别盈亏
    *getEchartDate2({ payload, callback }, { call, put }) {
      const response = yield call(api.profitOverview.getEchartDate2, payload);
      if (response && response.code == 0) {
        callback(response);
      } else {
        message.error(response && response.msg ? response.msg : '查询失败');
        console.error(`获取资产类别盈亏失败，失败原因：${response?.msg}`, 'majorAssetCount/ 接口：portfoliopnl/majorAssetCount/');
        callback({});
      }
    },
    // top / bottom
    *getEchartInfo({ payload, callback }, { call, put }) {
      const response = yield call(api.profitOverview.getEchartInfo, payload);
      if (response && response.code == 0) {
        callback(response);
      } else {
        message.error(response && response.msg ? response.msg : '查询失败');
        console.error(`获取top / bottom数据失败，失败原因：${response?.msg}`, 'majorAssetTop/ 接口：portfoliopnl/majorAssetTop/');
        callback({});
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
